package com.hmy.contract.controller;

import com.hmy.ccp.common.result.JsonResult;
import com.hmy.ccp.error.annotations.HmyGateWayController;
import com.hmy.contract.bo.request.authorizermodify.*;
import com.hmy.contract.service.authorizermodify.IAuthorizerModifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "授权人变更")
@RequestMapping("/api/authorizer/modify")
@HmyGateWayController
@Slf4j
public class AuthorizerModifyController {

    @Resource
    private IAuthorizerModifyService authorizerModifyService;

    @ApiOperation("保存")
    @PostMapping("/save")
    public JsonResult save(@RequestBody @Validated SaveAuthorizerModifyRequest request) {
        return JsonResult.success(authorizerModifyService.saveAuthorizerModify(request));
    }

    @ApiOperation("提交")
    @PostMapping("/submit")
    public JsonResult submit(@RequestBody @Validated SaveAuthorizerModifyRequest request) {
        return JsonResult.success(authorizerModifyService.submitAuthorizerModify(request));
    }

    @ApiOperation("撤销")
    @PostMapping("/revoke")
    public JsonResult revoke(@RequestBody @Validated RevokeAuthorizerModifyRequest request) {
        if (StringUtils.isBlank(request.getRemark())) {
            request.setRemark("发起人主动撤销");
        }
        return JsonResult.success(authorizerModifyService.revokeAuthorizerModify(request));
    }

    @ApiOperation("审批")
    @PostMapping("/approve")
    public JsonResult approve(@RequestBody @Validated ApproveAuthorizerModifyRequest request) {
        return JsonResult.success(authorizerModifyService.approveAuthorizerModify(request));
    }

    @ApiOperation("删除")
    @DeleteMapping("delete/{modifyId}")
    public JsonResult delete(@PathVariable("modifyId") Long modifyId) {
        return JsonResult.success(authorizerModifyService.deleteAuthorizerModify(modifyId));
    }

    @ApiOperation("查询详情")
    @PostMapping("query")
    public JsonResult query(@RequestBody QueryAuthorizerModifyRequest request) {
        return JsonResult.success(authorizerModifyService.queryAuthorizerModifyDetail(request));
    }

    @ApiOperation("列表分页查询")
    @PostMapping("queryByPage")
    public JsonResult queryByPage(@RequestBody QueryAuthorizerModifyRequest request) {
        return JsonResult.success(authorizerModifyService.queryAuthorizerModifyPage(request));
    }

    @ApiOperation("查询变更历史记录")
    @PostMapping("queryAuthorizerModifyHistory")
    public JsonResult queryAuthorizerModifyHistory(@RequestBody QueryAuthorizerModifyHistoryRequest request) {
        return JsonResult.success(authorizerModifyService.queryAuthorizerModifyHistory(request));
    }

}
